<?php
class Characters extends Zend_Db_Table_Abstract {
	protected $_name = 'characters';
	protected $_dependentTables = array('CharactersRolesRanks','RaidRosterChanges','RaidAdjustments','RaidDrops','RaidKillsParticipants');
	protected $_referenceMap = array(
		'User' 		=> 	array(
						'columns' 		=> array('user_id'),
						'refTableClass' => 'Users',
						'refColumns' 	=> array('id')
						),
		'Classes'	=> 	array(
						'columns'		=> array('class_id'),
						'refTableClass'	=> 'Classes',
						'refColumns'	=> array('id')
						)
	);
	
	/**
	 * Short hand for getting a raid by its id.
	 * 
	 * This function does mysql safe escaping on the raid id.
	 *
	 * @param 	int 			raid id
	 * @return 	TableRow|null
	 */
	public static function getById($characterId)
	{	
		// Raid id must be numeric
		if (!is_numeric($characterId)) {
			return null;
		}
		
		// Create static self
		$table = new self();
		
		// Create a select for getting the raid
		$select = $table->select()->where("id = ?", $characterId);
		$character = $table->fetchRow($select);
		
		// Return the raid or null
		if ($character) {
			return $character;
		} else {
			return null;
		}
	}
}
?>